import React from 'react'
import './index.css'
import { nanoid } from 'nanoid'
// 接受传参
export default function Header({ setTodoList, todoList }) {
 const   publishHandle  = (e) =>{
    if(e.keyCode !==13) return
    const publishValue = e.target.value.trim()
    if(!publishValue) return alert('请输入正确的内容')
    const newTodo = {id : nanoid(),todo :publishValue,done:false}
    setTodoList([newTodo, ...todoList])
    //清空输入框
    e.target.value = "";
 }
  return (
    <div className="todo-header">
    <input type="text" onKeyUp={publishHandle} placeholder="请输入你的任务名称，按回车键确认" />
  </div>
  )
}
